Filter module based on Section Number (Object Number)

Hello guys,

This is my first post in this forum :-D

I have seen a few threads in this forum about the use of Object Number.
I have a need to filter the module based on the section number (Object Number).

For example, if I only need to filter the section "3.1", I do not want the filtered display set to include objects of section "3.10", "3.11", etc.

So, I wrote the following code:
 

string objNo = "3.8.2.1.0"
int noOfChars = length objNo
 
// Validate only the last character to ensure that it is a number.
if( ((intOf objNo[noOfChars-1]) < 48 ) || ((intOf objNo[noOfChars-1]) > 57 ) )
{
    ack "Invalid section number: Shall end only with a number !"
        halt
}
 
Object othero = null
string s = null
 
filtering off
 
for othero in current Module do
{
        s = probeAttr_(othero,"Object Number")
 
        if( (s[0:(noOfChars-1)] == objNo) && ( (s[noOfChars:noOfChars] == "") || (s[noOfChars:noOfChars] == ".") || (s[noOfChars:noOfChars] == "-") ) )
                accept othero
        else
                reject othero
}
 
filtering on

 


The code works fine for all cases that I know of.
However, I feel there should be a better, more efficient way of doing the same thing.

I would be glad if you guys can give me your comments / suggestion to improve the code.

 


bullbala - Wed Feb 16 04:51:39 EST 2011

Re: Filter module based on Section Number (Object Number)
Mathias Mamsch - Wed Feb 16 11:45:17 EST 2011

How about a regular expression: regexp "^3.1($|^0-9)" ? You could only append that part ($|^0-9) to the object number to search. = 3.1 + end of string or a non-digit character ? You can also do this without a regular expression, look for the isdigit function to check for digits. Regards Mathias


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

Re: Filter module based on Section Number (Object Number)
Mathias Mamsch - Wed Feb 16 13:10:37 EST 2011

Mathias Mamsch - Wed Feb 16 11:45:17 EST 2011
How about a regular expression: regexp "^3.1($|^0-9)" ? You could only append that part ($|^0-9) to the object number to search. = 3.1 + end of string or a non-digit character ? You can also do this without a regular expression, look for the isdigit function to check for digits. Regards Mathias


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

Ok bad formatting. The regular expression should have been "^3.1($|[^0-9])"


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

Re: Filter module based on Section Number (Object Number)
bullbala - Thu Feb 17 00:04:47 EST 2011

Thank you for your response, Mathias.

In my code, I check for the 'end of string' character as
 

(s[noOfChars:noOfChars] == "")

 


I wanted to know if I can check the 'end of string' character as follows.

 

 

 

(null (s[noOfChars:noOfChars]))



I will try another version with regular expression shortly.

Here is the code now with your inputs:

VERSION 1 (without regular expression):



 

 

 

 

string objNo = "3.1"
int noOfChars = length objNo
 
// Validate the section number.
for(index = 0; index < noOfChars; index++)
{
    // If it is the last character ...
        if( index == (noOfChars - 1) )
        {
                // Validate the last character to ensure that it is only a digit.
                if(!isdigit objNo[index])
                {
                        ack "Invalid section number: Shall end only with a number !"
                        halt
                }
        }
        else
        {
                if( (!isdigit objNo[index]) && (objNo[index] != '.') && (objNo[index] != '-') )
                {
                        ack "Invalid section number: Shall contains only digits, '.' and '-' !"
                        halt
                }             
        }
}
 
Object othero = null
string s = null
 
filtering off
 
for othero in current Module do
{
        s = probeAttr_(othero,"Object Number")
 
        if( (s[0:(noOfChars-1)] == objNo) && ( (s[noOfChars:noOfChars] == "") || (s[noOfChars:noOfChars] == ".") || (s[noOfChars:noOfChars] == "-") ) )
                accept othero
        else
                reject othero
}
 
filtering on

 

 

Re: Filter module based on Section Number (Object Number)
PDU - Thu Feb 17 01:53:39 EST 2011

Hi,

perhaps i don't understand well the problem,

but why don't use filer : >= 3.1 AND < 3.10

Pierre

Re: Filter module based on Section Number (Object Number)
bullbala - Thu Feb 17 02:46:19 EST 2011

Thank you for your suggestion, Pierre.

I agree that the DOORS filter rule "(Object Number < 3.2) AND (Object Number >= 3.1)" would help me filter all objects in section "3.1".

However, I am planning to expand this code to a GUI and accept a string (read section number, say "3.1") from the user.
This way, I will save the user from the trouble of building rules for the filter :-)

I have made some improvement to the code I posted above:

VERSION I (without regular expression)
 

...
    if( (s[0:(noOfChars-1)] == objNo) && (!isdigit s[noOfChars]) )
                accept othero
        else
                reject othero
...

 


VERSION II (with regular expression)

 

 

 

...
    if (matches("^3\\.1(($)|([^0-9]))", s))
                accept othero
        else
                reject othero
...



Guys, does the above snippets look OK ?

P.S.
If I have to append the regular expression "(($)|(^0-9))" to the input string (section number) from the user, then do I first have to add double escape characters "\\" to every dot "." (and to every hyphen "-" ?) in the input string ?



 

 

Re: Filter module based on Section Number (Object Number)
Mathias Mamsch - Thu Feb 17 03:55:08 EST 2011

bullbala - Thu Feb 17 02:46:19 EST 2011

Thank you for your suggestion, Pierre.

I agree that the DOORS filter rule "(Object Number < 3.2) AND (Object Number >= 3.1)" would help me filter all objects in section "3.1".

However, I am planning to expand this code to a GUI and accept a string (read section number, say "3.1") from the user.
This way, I will save the user from the trouble of building rules for the filter :-)

I have made some improvement to the code I posted above:

VERSION I (without regular expression)
 

...
    if( (s[0:(noOfChars-1)] == objNo) && (!isdigit s[noOfChars]) )
                accept othero
        else
                reject othero
...

 


VERSION II (with regular expression)

 

 

 

...
    if (matches("^3\\.1(($)|([^0-9]))", s))
                accept othero
        else
                reject othero
...



Guys, does the above snippets look OK ?

P.S.
If I have to append the regular expression "(($)|(^0-9))" to the input string (section number) from the user, then do I first have to add double escape characters "\\" to every dot "." (and to every hyphen "-" ?) in the input string ?



 

 

Yeah, you are right, you would need to escape the '.' in the input string since "3.1" would also match 301.
So you better use the non regular expression variant. Interestingly you can use xlength x which does not yield an error. Therefore your code seems ok. Regards, Mathias
 

string x = "abc"
print isdigit x[3] // this works
print isdigit x[4] // -R-E- DXL: <Line:3> index beyond end of string [4]

 

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

 

Re: Filter module based on Section Number (Object Number)
bullbala - Thu Feb 17 04:36:26 EST 2011

Thank you Mathias & Pierre.

Mathias, I believe I have already used "length(string str)" to prevent use of an index beyond the end of string.
 

...
int noOfChars = length objNo
...
...
...
if( (s[0:(noOfChars-1)] == objNo) && (!isdigit s[noOfChars]) )
...

 


Were you talking about something else ?

 

Re: Filter module based on Section Number (Object Number)
Mathias Mamsch - Thu Feb 17 16:14:37 EST 2011

bullbala - Thu Feb 17 04:36:26 EST 2011

Thank you Mathias & Pierre.

Mathias, I believe I have already used "length(string str)" to prevent use of an index beyond the end of string.
 

...
int noOfChars = length objNo
...
...
...
if( (s[0:(noOfChars-1)] == objNo) && (!isdigit s[noOfChars]) )
...

 


Were you talking about something else ?

 

Yes. Your code is fine. I was surprised to see that you can index the end of the string, for example the string s = "abc" will have positions s[0],s[1],s[2] set to 'a','b' and 'c', but you still can do s[3] and will get a null char. I first thought that was a bug in your code but I tried it and it worked. Regards, Mathias

Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS